//
//  XLMessageCustomView.m
//  industry
//
//  Created by xl on 2020/11/26.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLMessageCustomView.h"

typedef void (^ButtonAction)(XLButton *);
@interface XLMessageCustomView ()<RPTaggedNavViewDelegate>

@property (nonatomic, copy) ButtonAction closeButtonClickBlock;
@property (nonatomic, copy) ButtonAction editButtonClickBlock;
@property (nonatomic, copy) ButtonAction selectButtonClickBlock;

@end

@implementation XLMessageCustomView


- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.deleteBtn];
        [self addSubview:self.editBtn];
        [self addSubview:self.allBtn];
        CGRect frame = self.segment.frame;
        frame.size = CGSizeMake(100, 35);
        [self.segment setDataArr:[NSArray arrayWithObjects:@"未读",@"已读", nil] with:frame];
        [self.searchBarView  changeTextFieldPlaceHolder:@"搜索未读信息"];
        
        [self setConstraints];
        
        
        
    }
    return self;
}

- (void)setConstraints {
    
    [_editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-30);
        make.centerY.equalTo(self.segment);
        make.size.mas_equalTo(CGSizeMake(44, 44));
    }];

    
    [_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(30);
        make.centerY.equalTo(self.editBtn);
        make.size.mas_equalTo(CGSizeMake(44 , 44));
    }];
    
    
    [_allBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-30);
        make.centerY.equalTo(self.editBtn);
        make.size.mas_equalTo(CGSizeMake(44, 44));
    }];
    
 
    

}

-(void)setEditButtonClickBlock:(void(^)(XLButton * button))editButtonClickBlock{
    _editButtonClickBlock = editButtonClickBlock;
}
-(void)setCloseButtonClickBlock:(void(^)(XLButton * button))closeButtonClickBlock{
    _closeButtonClickBlock = closeButtonClickBlock;
}
-(void)setSelectButtonClickBlock:(void(^)(XLButton * button))selectButtonClickBlock{
    _selectButtonClickBlock = selectButtonClickBlock;
}

#pragma mark - Public
- (void)changeEditStatus:(BOOL)status {
    if (status) {
        self.segment.hidden = YES;
        _editBtn.hidden = YES;
        _deleteBtn.hidden = NO;
        _allBtn.hidden = NO;
    } else {
        self.segment.hidden = NO;
        _editBtn.hidden = NO;
        _deleteBtn.hidden = YES;
        _allBtn.hidden = YES;
    }
}

#pragma mark - setter/getter

- (XLButton *)deleteBtn {
    if (!_deleteBtn) {
        _deleteBtn = [XLButton new];
        [_deleteBtn setImage:XLIMAGE(@"qx") forState:UIControlStateNormal];
        _deleteBtn.hidden = YES;
        WEAKSELF
        [_deleteBtn setButtonAction:^(XLButton * _Nonnull button) {
            weakSelf.closeButtonClickBlock(button);
        }];
    }
    return _deleteBtn;
}

- (XLButton *)editBtn {
    if (!_editBtn) {
        _editBtn = [XLButton new];
        [_editBtn setImage:XLIMAGE(@"xxbj") forState:UIControlStateNormal];
        WEAKSELF
        [_editBtn setButtonAction:^(XLButton * _Nonnull button) {
            weakSelf.editButtonClickBlock(button);
        }];
    }
    return _editBtn;
}

- (XLButton *)allBtn {
    if (!_allBtn) {
        _allBtn = [XLButton new];
        _allBtn.hidden = YES;
        _allBtn.titleLabel.font = [UIFont fontOfPingFangSCRegularWithSize:14];
        [_allBtn setTitleColor:[UIColor grayFontColor] forState:UIControlStateNormal];
        [_allBtn setTitle:@"全选" forState:UIControlStateNormal];
        [_allBtn setTitle:@"全不选" forState:UIControlStateSelected];
        WEAKSELF
        [_allBtn setButtonAction:^(XLButton * _Nonnull button) {
            button.selected = !button.selected;
            weakSelf.selectButtonClickBlock(button);
        }];
    }
    return _allBtn;
}
@end
